import os
import os.path
import pandas as pd

class DirWalk():
    def __init__(self,dir_path,file_type="excel"):
        '''
        '''
        self._dp = dir_path
        self._type = file_type
        self._fs = self._getPathStruct()

    def _getPathStruct(self):
        if not self._dp:
            return None

        if self._type == 'excel':
            use_ext = ['xlsx','xls','XLSX','XLS']
        else:
            use_ext = [self._type]

        file_struct_df = pd.DataFrame(columns=['文件名称','文件路径'])
        for root,dirs,files in os.walk(self._dp):
            for file in files:
                if os.path.splitext(file)[1][1:] in use_ext:
                    file_path = os.path.join(root,file)
                    file_struct_df.loc[file_struct_df.shape[0],:] = os.path.splitext(os.path.basename(file))[0],file_path
        return file_struct_df

    def getDirStruct(self):
        return self._fs

if __name__ == "__main__":
    dw = DirWalk("2020年",'excel')
